package com.zj.core.ui

import android.support.constraint.ConstraintLayout
import android.view.View
import android.view.ViewGroup
import android.view.ViewManager
import android.widget.LinearLayout
import com.zj.core.view.MeuseTextView
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout
import org.jetbrains.anko.custom.ankoView

class TemplateChildUi: AnkoComponent<ViewGroup> {
    override fun createView(ui: AnkoContext<ViewGroup>): View = with(ui){
        constraintLayout {
            lparams(width= matchParent,height = wrapContent){
                leftMargin=dip(30)
                rightMargin=dip(10)
            }

            view{
                id= R.id.record_item_line
                visibility= View.GONE
                backgroundColor=resources.getColor(R.color.black_translucent)
            }.lparams(width= matchParent,height = dip(1)){
                bottomToTop= R.id.check_box_view
            }

            checkBox {
                id= R.id.check_box_view
            }.lparams(width= wrapContent,height = wrapContent){
                leftToLeft= ConstraintLayout.LayoutParams.PARENT_ID
                rightToLeft= R.id.item_serial_number
                topToBottom= R.id.record_item_line
            }

            meusetextview {
                id= R.id.template_str_tv
                maxLines=1
                textSize=dip(10).toFloat()
            }.lparams(width=0,height = LinearLayout.LayoutParams.WRAP_CONTENT){
                leftMargin=dip(5)
                rightMargin=dip(5)
                topMargin=dip(15)
                topToBottom= R.id.record_item_line
                leftToRight= R.id.check_box_view
                rightToLeft= R.id.push_img_view
            }

            imageView {
                id= R.id.push_img_view
                visibility= View.INVISIBLE
                background=resources.getDrawable(R.mipmap.detail_img)
            }.lparams(width=dip(25),height = dip(25)){
                topToTop= R.id.check_box_view
                bottomToBottom= R.id.check_box_view
                leftToRight= R.id.template_str_tv
                rightToRight= ConstraintLayout.LayoutParams.PARENT_ID
            }
        }
    }

    inline fun ViewManager.meusetextview(theme: Int = 0, init: MeuseTextView.() -> Unit) : MeuseTextView {
        return ankoView({ MeuseTextView(it) }, theme, init)
    }
}